package my.springboot3.service.impl;

import my.springboot3.dto.entity.Category;
import my.springboot3.mapper.CategoryMapper;
import my.springboot3.service.CategoryService;
import my.springboot3.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class  CategoryServiceImpl implements CategoryService {
    @Autowired
    private CategoryMapper categoryMapper;

    /**
     * 查询所有分类
     *
     * @return
     */
    @Override
    public List<Category> ListAll() {
        return categoryMapper.findAll();
    }

    /**
     * 根据id查询分类
     */
    @Override
    public Category findById(Integer id) {
        return categoryMapper.findById(id);
    }

    /**
     * 修改分类
     */
    @Override
    public void update(Category category) {
        categoryMapper.update(category);
    }

    /**
     * 根据id删除分类
     */
    @Override
    public void deleteById(Integer id) {
        categoryMapper.deleteById(id);
    }

    /**
     * 添加分类
     */
    @Override
    public void add(Category category) {
        //获取当前登录用户的id,并赋值给create_user字段
        Integer id = (Integer)ThreadLocalUtil.get();
        category.setCreateUser(id);
        categoryMapper.add(category);
    }
}
